// 
// File:   bot.h
// Author: dnazarov
//
// Created on 5 Октябрь 2009 г., 14:28
//

#ifndef _BOT_H
#define	_BOT_H

#include <gloox/client.h>
#include <gloox/messagehandler.h>
#include <gloox/presencehandler.h>
#include <gloox/connectionlistener.h>
#include <string>
#include "../serversocket.h"
#include "data.h"
#include <list>
#include "../cfgparser.h"

class Bot : public gloox::MessageHandler, gloox::PresenceHandler
{
public:

    Bot();
    ~Bot();


    virtual void onConnect();
    virtual bool onTLSConnect(const gloox::CertInfo& info);
    int SendMsg(const std::string &);
    void connect();
    void listen();
    void reply(const std::string &msg);
    bool request(const std::string &, const std::string &);

    bool getStatus()
    {
        return m_status;
    }

    void setAvailableHosts(const std::string &str)
    {
        m_available_hosts = str;
    }

private:

    void replace(std::string &, const std::string &, const std::string &);
    bool requestWrapper(const std::string &, const std::string &);
    virtual void handleMessage(gloox::Stanza *, gloox::MessageSession *session = 0);
    gloox::Client *m_client;
    virtual void handlePresence(gloox::Stanza *);
    Data * m_data;
    CfgParser * m_server_config;
    const std::list<std::string> * m_users;
    std::string m_sender, m_available_hosts, m_admins;
    bool m_toAll;
    bool m_status;
    std::string m_eol;
    vector<string> * m_agent_ips;
    vector<string> * m_agent_hosts;

};

#endif	/* _BOT_H */